﻿@using CNKI.TPI.Web.Base
@using CNKI.TPI.Web.Search.Model;
<script>
    function favShow() {
        $.ajax({
            type: "GET",
            url: timestamp("@Html.Raw(Url.Action("GetFavList", "UserCenter"))"),
        beforeSend: function () { $("#loading").show(); },
        success: function (msg) {
            var obj = eval(msg);
            $(".ulfield").empty();
            if (obj != null && obj.length > 0) {
                for (var i = 0; i < obj.length; i++) {
                    var listr = " <li class=\"f-ct\" style=\"margin-left: 2em;\">  <label class=\"f-label block right\">" +
                   " <input type=\"radio\" name=\"favcate\" class=\"f-checkboxR\"  value='" + obj[i].FavoriteCategoryID + "' />" + obj[i].CategoryName + "</label></li>";
                    $(".ulfield").append(listr);
                }
                //默认第一个选中
                $('input:radio:first').attr('checked', 'checked');
            }
            $("#loading").hide();
        },
        error: function (e)
        { $("#loading").hide(); }

    })
        $(".message").show();
    }
    function favClose() {
        $(".message").hide();
    }
    function clickfav(recID, recTitle, sortno, flage) {
        ;
        $("#recTitle").val(recTitle);
        $("#recID").val(recID);
        $("#sortno").val(sortno);
        $("#flage").val(flage);//0 列表模式，1 摘要模式
        //默认第一个选中
        $('input:radio:first').attr('checked', 'checked');
        favShow();
    }
    //保存收藏
    function savefav() {
        ;
        var dbCode = $("#dbCode").val();
        var dbName = $("#DisplayDBName").val();
        var recID = $("#recID").val();
        var recTitle = $("#recTitle").val();
        var favid = $("input[name='favcate']:checked").val();
        var saveurl = "@Html.Raw(Url.Action("InsertFavoriteFolder", "UserCenter"))";
        $.ajax({
            type: "POST",
            data: { "favCateID": favid, "dbCode": dbCode, "dbName": dbName, "recid": recID, "recTitle": recTitle },
            url: saveurl,
            success: function (f) {
                if (f == "True") {
                    var index = $("#sortno").val();//当前收藏的行
                    var flage = $("#flage").val();
                    var str = "<a href=\"javascript:void(0);\" onclick=\"canclefav('" + recID + "','" + recTitle + "','" + index + "','" + flage + "')\"  title=\"取消收藏\" class='iconfont link-gray icon-star'</a>";
                    var page = $("#pagenow").val();
                    var f = (page - 1) * 10;  //10条一页， index-f 为点击table的某一行
                    if (flage == 0)//table 列表模式
                    {
                        $("#table_list").find("tr").eq(index - f).find("td:last").html(str);//当前行最后一列
                    }
                    else {  //摘要模式
                        $("#ul_abstract li").eq(index - f - 1).find("#favspan").html(str);

                    }
                    favClose();
                }
                else {
                    messageAlert("操作失败！");
                }
            },
            error: function (e)
            { }
        })
    }
    //取消收藏
    function canclefav(recID, recTitle, index, flage) {
        ;
        var saveurl = "@Html.Raw(Url.Action("CancelFavByRecID", "UserCenter"))";
        $.ajax({
            type: "POST",
            data: { "recid": recID },
            url: saveurl,
            success: function (f) {
                if (f == "True") {
                    var str = "<a href=\"javascript:void(0);\" class='iconfont link-gray icon-star1'  onclick=\"clickfav('" + recID + "','" + recTitle + "','" + index + "','" + flage + "')\"  title=\"收藏\"></a>";
                    var page = $("#pagenow").val();
                    var f = (page - 1) * 10;  //10条一页， index-f 为点击table的某一行
                    if (flage == 0)//table 列表模式
                    {
                        $("#table_list").find("tr").eq(index-f).find("td:last").html(str);//当前行最后一列
                    }
                    else {  //摘要模式
                        $("#ul_abstract li").eq(index - f - 1).find("#favspan").html(str);

                    }
                    favClose();
                }
                else {
                    messageAlert("操作失败！");
                }
            },
            error: function (e)
            { }
        })
    }
</script>
<div class="order-box clearfix">
    @*排序*@
    <div class="fl">
        <label class="f-label" style="display: none">
            <input type="checkbox">全选
        </label>
        <label class="f-label" style="display: none"><i class="iconfont icon-star"></i>收藏</label>
        <span class='taxis'>
            排序：
            @if (ViewBag.SortField != null)
            {
                foreach (var item in ViewBag.SortField)
                {
                    if (@ViewBag.SortFiledNow == @item.FieldName)
                    {
                        <a href="javascript:void(0);" class='cur' onclick="sortClick('@ViewBag.SortDescAsc','@item.FieldName')">
                            @item.FieldDispName
                            @if (@ViewBag.SortDescAsc == "desc")
                        {<i class="iconfontdesc"></i>}
                        else
                        {<i class="iconfontasc"></i>}
                        </a>
                    }
                    else
                    {
                        <a href="javascript:void(0);" onclick="sortClick('@ViewBag.SortDescAsc','@item.FieldName')">@item.FieldDispName</a>
                    }
                }
            }
        </span>
    </div>
    @*显示模式及分页汇总*@
    <div class="fr order-r">
        <div class="lb">
            @{string strlist = "";
                string strabstract = "";
                if (ViewBag.listAbstract == "list")
                {
                    strlist = "class=cur";
                }
                else
                {
                    strabstract = "class=cur";
                }
                <a href="javascript:void(0);" @strlist onclick="formatList('list')"><i class="iconfont iconfont-list"></i>列表</a>
                <a href="javascript:void(0);" @strabstract onclick="formatList('abct')"><i class="iconfont iconfont-abstract"></i>摘要</a>
            }
            @{if (@ViewBag.TotalPage == 0)
                {
                    <span>0 条结果 0 /0</span>
                }
                else
                {
                    <span>@ViewBag.ResultCount 条结果 @ViewBag.PageNow /@ViewBag.TotalPage</span>
                }
            }
            @if (ViewBag.TotalPage > 0 && ViewBag.PageNow != ViewBag.TotalPage)
            {
                int nextpage = ViewBag.PageNow + 1;
                <a href="javascript:void(0);" style="border:0px" class="next-t" onclick="searchPageNew('@nextpage')"></a>
            }
            else
            {
                <a href="javascript:void(0);" style="border: 0px" class="next-t disable"></a>
            }
        </div>
    </div>
</div>
@* “全文下载”弹层 *@
<div class="talkDiv Down" style="display: none; top: 250px">
    <div class="talkDiv-title" style="line-height: 40px; padding-left: 10px; font-size: 16px; border-bottom: 1px solid #DADADA; background-color: #efefef; font-family: 微软雅黑">
        <span>下载</span>
        <a class="icon icon-close" title="关闭" href="javascript:void(0);" onclick="closedown()" style="top: 15px"><i class="iconfont icon-error3"></i></a>
    </div>
    <div class="talkDiv-body" style="padding-top: 25px">
        <ul class="video-download"></ul>
    </div>
</div>
@{if (ViewBag.listAbstract == "list")
    {
        // 列表显示
        <table width="100%" cellspacing="0" cellpadding="0" border="0" class="table table-grey" id="table_list">
            <thead>
                <tr class="thead">
                    <th class="tdnum">序号</th>
                    @{ System.Data.DataRow columnInfo = null;
                        System.Data.DataRow[] columnInfoList = null;}
                    @foreach (System.Data.DataColumn item in ViewBag.SearchResult.Columns)
                    {
                        columnInfoList = ViewBag.ResultColumnInfo.Select(string.Format("Name='{0}'", item.ColumnName));
                        if (columnInfoList.Length > 0)
                        {
                            columnInfo = columnInfoList[0];

                            //if ((!columnInfo["Name"].ToString().StartsWith("SYS_FLD_SYSID")) && (!columnInfo["DispName"].ToString().Equals("摘要")))
                            if ((!columnInfo["Name"].ToString().StartsWith("SYS_FLD_SYSID")))
                            {
                                <th width="@columnInfo["Width"]%">@columnInfo["DispName"]</th>
                            }
                        }
                    }
                    @if (ViewBag.SearchResult.Columns.Contains("SYS_FLD_SYSID") && SessionHelper.HasDownloadRight(ViewBag.dbId))
                {
                        <th>下载</th>
                    }
                    @if (SessionHelper.GetUserInfo() != null
&& ((ConfigHelper.IsAnonymousControlEnabled() && SessionHelper.GetUserInfo().UserCode.ToUpper() != ConfigHelper.GetAnonymousAccount().ToUpper())
|| !ConfigHelper.IsAnonymousControlEnabled()))
                    {
                        <th>收藏</th>
                    }
                </tr>
            </thead>
            <tbody>
                @{int sortno = ViewBag.PageSize * (ViewBag.PageNow - 1) + 1;
                    string str = "";
                    foreach (System.Data.DataRow dr in ViewBag.SearchResult.Rows)
                    {
                        int j = 0;
                        <tr>
                            <td style="word-break: normal" class="tc">
                                <input name="" type="checkbox" value="" style="display: none" />@sortno
                            </td>
                            @foreach (System.Data.DataColumn column in ViewBag.SearchResult.Columns)
                    {
                        if (j == 0)//第一列加链接
                        {
                            str = StringHelper.UnDealInfo(ColumnAliasHelper.GetContent(dr, ViewBag.DbName, column.ColumnName));
                                    <td>
                                        <a target="_blank" href="@dr["SYS_FLD_URL"]">
                                            @Html.Raw(ColumnAliasHelper.SubContent(str, ConfigHelper.GetSearchResultCutLengh()))
                                        </a>
                                    </td>
                                }
                                else
                                {
                                    if (column.ColumnName.StartsWith("SYS_FLD_SYSID") || column.ColumnName == "__sys_from"
                                        //|| column.ColumnName == ColumnAliasHelper.GetColumn(@ViewBag.DbName, "摘要")
                                        || ViewBag.ResultColumnInfo.Select(string.Format("Name='{0}'", column.ColumnName)).Length == 0)
                                    {
                                        //<td style="display: none"></td>
                                    }
                                    else
                                    {
                                        if (column.ColumnName == ColumnAliasHelper.GetColumn(@ViewBag.DbName, "发表时间"))
                                        {
                                            <td style="width: 100px; text-align: center">@Html.Raw(ColumnAliasHelper.GetContent(dr, ViewBag.DbName, column.ColumnName))</td>
                                        }
                                        else
                                        {
                                            <td>@Html.Raw(ColumnAliasHelper.GetContent(dr, ViewBag.DbName, column.ColumnName))</td>
                                        }
                                    }
                                }
                                j++;
                            }
                            @if (dr.Table.Columns.Contains("SYS_FLD_SYSID") && SessionHelper.HasDownloadRight(ViewBag.dbId))
                    {
                                <td class="tc">
                                    @{
                                        int type = (int)MediaType.Doc;
                                        int downtype = (int)DownFromType.CommonDown;
                                        <a onclick="downfilelist('@ViewBag.dbId','@dr["SYS_FLD_SYSID"].ToString()','@ViewBag.DbName','@type','@Html.Raw(Url.Action("IsShowDown", "File"))','@Html.Raw(Url.Action("GetFilesByRecordID", "SingleSearch"))','@downtype')" class='icon-star iconfont icon-xiajiantou2 link-gray' title="下载" href='javascript:;'></a>
                                    }
                                </td>
                                        }
                            @if (SessionHelper.GetUserInfo() != null
&& ((ConfigHelper.IsAnonymousControlEnabled() && SessionHelper.GetUserInfo().UserCode.ToUpper() != ConfigHelper.GetAnonymousAccount().ToUpper())
|| !ConfigHelper.IsAnonymousControlEnabled()))
                            {
                                <td class="tc">
                                    @{
                                string key = "";
                                switch ((SearchType)ViewBag.SearchType)
                                {
                                    case SearchType.TPI:
                                        key = "SYS_FLD_SYSID";
                                        break;
                                    case SearchType.CNKI:
                                        key = ConfigHelper.GetCNKIResourceKey();
                                        break;
                                    case SearchType.KSPIRDER:
                                        key = ConfigHelper.GetKspiderKey();
                                        break;
                                    default:
                                        key = "SYS_FLD_SYSID";
                                        break;
                                }
                                string listrecordid = ViewBag.FavList;
                                string thisid = "," + dr[key].ToString() + ",";
                                if (listrecordid.Contains(thisid)) //已经被收藏
                                {
                                    <a href="javascript:void(0);" onclick="canclefav('@dr[key].ToString()','@StringHelper.RemoveHighlightTag(str)','@sortno',0)" title="取消收藏" class='iconfont link-gray icon-star'></a>
                                }
                                else
                                {
                                    <a href="javascript:void(0);" onclick="clickfav('@dr[key].ToString()','@StringHelper.RemoveHighlightTag(str)','@sortno',0)" class='iconfont link-gray icon-star1' title="收藏"></a>
                                }
}
                                </td>
                                        }
                        </tr>
                                            sortno = sortno + 1;
                                        }
                }
            </tbody>
        </table>
                                        }
                                        else
                                        {
                                            // 摘要显示
                                            <ul class="abstract" id="ul_abstract">
                                                @{int abstractno = ViewBag.PageSize * (ViewBag.PageNow - 1) + 1;
                                                    string titlestr = "";
                                                    foreach (System.Data.DataRow dr in ViewBag.SearchResult.Rows)
                                                    {
                                                        <li>
                                                            @{
                                                                int m = 0;
                                                                System.Data.DataRow columnInfo = null;
                                                                System.Data.DataRow[] columnInfoList = null;
                                                                foreach (System.Data.DataColumn column in ViewBag.SearchResult.Columns)
                                                                {
                                                                    columnInfoList = ViewBag.ResultColumnInfo.Select(string.Format("Name='{0}'", column.ColumnName));
                                                                    if (columnInfoList != null && columnInfoList.Length > 0)
                                                                    {
                                                                        columnInfo = columnInfoList[0];
                                                                        if (m == 0) //第一列加超链接
                                                                        {
                                                                            titlestr = StringHelper.UnDealInfo(dr[column.ColumnName].ToString());
                                                                            titlestr = StringHelper.RemoveHighlightTag(titlestr);
                                                                            <h2 class=''><a target="_blank" href="@dr["SYS_FLD_URL"]">@abstractno、 @Html.Raw(dr[column.ColumnName].ToString())</a></h2>
                                                                        }
                                                                        else if (m != 0 && !column.ColumnName.StartsWith("SYS_FLD")) //排除第一列标题列和系统字段
                                                                        {
                                                                            string colname = column.ColumnName;
                                                                            if (!string.IsNullOrEmpty(columnInfo["DispName"].ToString()))
                                                                            {
                                                                                colname = columnInfo["DispName"].ToString();
                                                                            }
                                                                            if (!string.IsNullOrEmpty(dr[column.ColumnName].ToString()))
                                                                            {
                                                                                <p>@colname:  <span class="writer">@Html.Raw(dr[column.ColumnName].ToString())</span></p>
                                                                            }
                                                                        }
                                                                        m++;
                                                                    }
                                                                }
                                                                <div class="detail tr">
                                                                    @if (dr.Table.Columns.Contains("SYS_FLD_BROWSERATE"))  //浏览量
                                                                    {

                                                                        columnInfoList = ViewBag.ResultColumnInfo.Select(string.Format("Name='{0}'", "SYS_FLD_BROWSERATE"));
                                                                        if (columnInfoList != null && columnInfoList.Length > 0)
                                                                        {
                                                                            columnInfo = columnInfoList[0];
                                                                            <span>@columnInfo["DispName"].ToString(): @Html.Raw(dr["SYS_FLD_BROWSERATE"].ToString() == "" ? "0" : dr["SYS_FLD_BROWSERATE"].ToString())</span>
                                                                        }
                                                                    }
                                                                    @if (dr.Table.Columns.Contains("SYS_FLD_DOWNLOADRATE"))//下载量
                                                                    {

                                                                        columnInfoList = ViewBag.ResultColumnInfo.Select(string.Format("Name='{0}'", "SYS_FLD_DOWNLOADRATE"));
                                                                        if (columnInfoList != null && columnInfoList.Length > 0)
                                                                        {
                                                                            columnInfo = columnInfoList[0];
                                                                            <span>@columnInfo["DispName"].ToString(): @Html.Raw(dr["SYS_FLD_DOWNLOADRATE"].ToString() == "" ? "0" : dr["SYS_FLD_DOWNLOADRATE"].ToString())</span>
                                                                        }
                                                                    }
                                                                    @if (dr.Table.Columns.Contains("SYS_FLD_SYSID") && SessionHelper.HasDownloadRight(ViewBag.dbId))//下载
                                                                    {
                                                                        int type = (int)MediaType.Doc;
                                                                        int downtype = (int)DownFromType.CommonDown;
                                                                        <a onclick="downfilelist('@ViewBag.dbId','@int.Parse(dr["SYS_FLD_SYSID"].ToString())','@ViewBag.DbName','@type','@Html.Raw(Url.Action("IsShowDown", "File"))','@Html.Raw(Url.Action("GetFilesByRecordID", "SingleSearch"))','@downtype')" class='icon-star iconfont icon-xiajiantou2 link-gray mr10' title="下载" href='javascript:;'></a>
                                                                    }
                                                                    @if (SessionHelper.GetUserInfo() != null
&& ((ConfigHelper.IsAnonymousControlEnabled() && SessionHelper.GetUserInfo().UserCode.ToUpper() != ConfigHelper.GetAnonymousAccount().ToUpper())
|| !ConfigHelper.IsAnonymousControlEnabled()))
                                                                    {
                                                                        <span id="favspan">
                                                                            @{
                                                                        string key = "";
                                                                        switch ((SearchType)ViewBag.SearchType)
                                                                        {
                                                                            case SearchType.TPI:
                                                                                key = "SYS_FLD_SYSID";
                                                                                break;
                                                                            case SearchType.CNKI:
                                                                                key = ConfigHelper.GetCNKIResourceKey();
                                                                                break;
                                                                            case SearchType.KSPIRDER:
                                                                                key = ConfigHelper.GetKspiderKey();
                                                                                break;
                                                                            default:
                                                                                key = "SYS_FLD_SYSID";
                                                                                break;
                                                                        }
                                                                        string listrecordid = ViewBag.FavList;
                                                                        string thisid = "," + dr[key].ToString() + ",";
                                                                        if (listrecordid.Contains(thisid)) //已经被收藏
                                                                        {
                                                                            <a href="javascript:void(0);" onclick="canclefav('@dr[key].ToString()','@titlestr','@abstractno',1)" title="取消收藏" class='iconfont link-gray icon-star'></a>
                                                                        }
                                                                        else
                                                                        {
                                                                            <a href="javascript:void(0);" onclick="clickfav('@dr[key].ToString()','@titlestr','@abstractno',1)" class='iconfont link-gray icon-star1' title="收藏"></a>
                                                                        }
}
                                                                        </span>
                                                                                }
                                                                </div>
                                                            }
                                                        </li>
                                                                                    abstractno = abstractno + 1;
                                                                                }
                                                }
                                            </ul>
                                                                                }
}
@*//分页*@
<div class="pagenav pagenav-02">
    @if (ViewBag.TotalPage > 0)
    {
        @*上一页*@
    if (ViewBag.PageNow != 1)
    {
        int thispage = ViewBag.PageNow - 1;
        <a href="javascript:void(0);" class="page-prev" onclick="searchPageNew('@thispage')">上一页</a>
    }
    else
    {
        <a href="javascript:return false;" class="page-prev disable" onclick="return false">上一页</a>
    }
    @*循环初始化页码*@
    foreach (string numpage in ViewBag.PageList)
    {
        if (numpage != "0")
        {
            int m = int.Parse(numpage);
            if (m == ViewBag.PageNow)
            {
                <a href="javascript:void(0);" class="active" onclick="searchPageNew('@numpage')">@numpage</a>

            }
            else
            {
                <a href="javascript:void(0);" onclick="searchPageNew('@numpage')">@numpage</a>
            }

        }
        else
        {
            <i class="iconfont icon-dian2"></i>
        }

    }
    @*下一页*@
    if (ViewBag.PageNow != ViewBag.TotalPage)
    {
        int nextpage = ViewBag.PageNow + 1;
        <a href="javascript:void(0);" class="page-next" onclick="searchPageNew('@nextpage')">下一页</a>
    }
    else
    {
        <a href="javascript:return false;" class="page-prev disable" onclick="return false">下一页</a>
        }
    }
    else
    {
        <label>暂无数据！</label>

    }

</div>
@*//收藏*@
<div class="talkDivBg-message message" style="z-index: 999;">
    <div class="talkDiv talkDivTr talkW-550 form-h message" style="margin-top: -278px; display: none">
        <div class="talkDiv-title" style="padding-top: 10px">
            <h3 class='bbsolid'><i class="blue-block"></i><span>收藏分类</span></h3>
        </div>
        <div class="talkDiv-body talkDiv-body1" id="messageDiv" style="padding: 0px 40px 10px">
            <ul class="ulfield">
            </ul>
        </div>
        <div class="f-gp" style="margin-left: 60px; padding-bottom: 30px; margin-top: 5px">
            <div class="f-ct">
                <button id="btnSubmit" class="btn btn-m btn-prim-f btn-submit" onclick="savefav()">确定</button>
                &nbsp;&nbsp
                <a href="javascript:void(0);" id="btnClose" class="btn btn-m btn-submit btn-defa-f" onclick="favClose()">取消</a>
            </div>
        </div>
    </div>
</div>

<input type="hidden" id="dbCode" name="dbCode" value="@ViewBag.DbName" />
<input type="hidden" id="dbName" name="dbName" value="@ViewBag.DisplayDBName" />
<input type="hidden" id="recID" name="recID" value="0" />
<input type="hidden" id="recTitle" name="recTitle" value="" />
<input type="hidden" id="flage" name="flage" value="0" />
<input type="hidden" id="sortno" name="sortno" value="0" />
<input type="hidden" id="pagenow" name="pagenow" value="@ViewBag.PageNow" />